package cn.jroid.demo.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.jroid.demo.R;
import cn.jroid.demo.entity.User;
import cn.jroid.demo.entity.UserList;

public class UserListAdapter extends BaseAdapter {
	
	private Context context;
	private List<User> list = new ArrayList<User>();
	
	public UserListAdapter(Context context, UserList userList) {
		this.context = context;
		this.list = userList.getUserList();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LinearLayout linearLayout = (LinearLayout)LayoutInflater.from(context).inflate(R.layout.user_list_item, null);
		User user = (User) list.get(position);
		ImageView imageView = (ImageView)linearLayout.findViewById(R.id.image);
		TextView usernameTextView = (TextView)linearLayout.findViewById(R.id.username);
		TextView contentTextView = (TextView)linearLayout.findViewById(R.id.content);
		imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_launcher));
		usernameTextView.setText(user.getUsername());
		contentTextView.setText(user.getContent());
		return linearLayout;
	}

}
